import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class CsvToXlsx {

public static void main(String args[]) throws IOException
{ 
    ArrayList arList=null;
    ArrayList al=null;
    String sym = "rilbo";
    String fName = "D:/project/src/java/quotes/"+sym+".csv";
    String thisLine; 
     
    FileInputStream fis = new FileInputStream(fName);
    DataInputStream myInput = new DataInputStream(fis);
    int i=0;
    arList = new ArrayList();
    
    while ((thisLine = myInput.readLine()) != null)
    {
        al = new ArrayList();
        String strar[] = thisLine.split(",");
        for(int j=0;j<strar.length;j++) //can optimize(see in NetBeans but do not do it without partner discussion)
        {
            al.add(strar[j]);
        }
        arList.add(al);
        i++;
    } 

    try
    {
        XSSFWorkbook hwb = new XSSFWorkbook();
        XSSFSheet sheet = hwb.createSheet("new sheet");
        for(int k=0;k<arList.size();k++)
        {
            ArrayList ardata = (ArrayList)arList.get(k);
            XSSFRow row = sheet.createRow((short) 0+k);
            for(int p=0;p<ardata.size();p++)
            {
                XSSFCell cell = row.createCell((short) p);
                String data = ardata.get(p).toString();
                
                if(data.matches("^\\d*\\.?\\d*$"))
                {
                    cell.setCellValue(Double.parseDouble(data));
                }
                else
                {
                    cell.setCellValue((data));
                }
            }
       }
       System.out.println();
     
     FileOutputStream fileOut = new FileOutputStream("D:/project/src/java/quotes/"+sym+".xlsx");
     
     hwb.write(fileOut);
     fileOut.close();
     System.out.println("Your excel file has been generated");
    } 
    
    catch ( Exception ex ) {ex.printStackTrace();} 
} 
}